智能计数计算机视觉 opencv 物体数数.ipynb import cv2import imutils
image = cv2.imread("D:/jupyter file/image/29.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
edged = cv2.Canny(blurred, 50, 130)
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
total = 0
for c in cnts:
if cv2.contourArea(c) < 25: #这个值要调参数
continue
cv2.drawContours(image, [c], -1, (204, 0, 255), 2)
total = 1
print("[INFO] found {} shapes".format(total))
cv2.imshow("Image", image)
cv2.waitKey(0)
cv2.waitKey(0)
cv2.destroyAllWindows()
评论